﻿using System;
using System.Collections;
using System.ComponentModel;
using System.Drawing;
using System.Windows.Forms;

namespace DBService
{
	public partial class DlgPorjectUserApproval : System.Windows.Forms.Form
	{
		public DlgPorjectUserApproval()
		{
			try
			{
				this.InitializeComponent();
				foreach (DbProjectUserRelation dbProjectUserRelation in DbProjectUserRelation.GetInvalidRelation(BimServerDB.Default))
				{
					this.dgvUser.Rows.Add(new object[]
					{
						dbProjectUserRelation.User.Name,
						dbProjectUserRelation.Project.ToString(),
						dbProjectUserRelation.UserTypeString,
						false,
						dbProjectUserRelation.User.Id,
						dbProjectUserRelation.Project.Id,
						(int)dbProjectUserRelation.UserType
					});
				}
			}
			catch
			{
			}
		}

		private void btnOK_Click(object sender, EventArgs e)
		{
			if (this.dgvUser.Rows.Count > 0)
			{
				foreach (object obj in ((IEnumerable)this.dgvUser.Rows))
				{
					DataGridViewRow dataGridViewRow = (DataGridViewRow)obj;
					DbUser fromDB = DbUser.GetFromDB(Convert.ToInt32(dataGridViewRow.Cells["userId"].Value), BimServerDB.Default);
					DbProject fromDB2 = DbProject.GetFromDB(Convert.ToInt32(dataGridViewRow.Cells["projectId"].Value), BimServerDB.Default);
					UserType type = (UserType)Convert.ToInt32(dataGridViewRow.Cells["userType"].Value);
					if (fromDB != null && (bool)dataGridViewRow.Cells["Verify"].Value)
					{
						fromDB.Approval(type, fromDB2);
						DbUser.System.SendMessage(fromDB.Name, "您加入项目" + dataGridViewRow.Cells["ProjectName"].Value.ToString() + "的申请已经被审核。");
					}
				}
				MessageBox.Show("用户已审核完成！");
			}
			base.Close();
		}

		private void DlgPorjectUserApproval_Load(object sender, EventArgs e)
		{
		}
	}
}
